package mysql

import "gorm.io/gorm"

type Goods struct {
	gorm.Model
	GoodsTitle string  `gorm:"type:varchar(100)"`
	GoodsStock int     `gorm:"type:int(10)"`
	GoodsCover string  `gorm:"type:varchar(200)"`
	GoodsPrice float64 `gorm:"type:decimal(10,2)"`
	GoodsSales int     `gorm:"type:int(10)"`
	Status     int     `gorm:"type:int(10);default1;comment:1:已审核;2:未审核;3:审核未通过;"`
}

func (g *Goods) GetGoods(GoodsId int64) error {
	return DB.Where("id = ?", GoodsId).Limit(1).Find(&g).Error
}
func (g *Goods) Create() error {
	return DB.Create(&Goods{}).Error
}
func (g *Goods) GetGoodsList() (List []*Goods, err error) {
	//if status == 0 {
	//	err = DB.Where("status = ?", 1).Find(&List).Error
	//} else {
	//	err = DB.Where("status", status).First(&List).Error
	//}
	err = DB.Where("status = ?", 1).Order("goods_sales asc").Find(&List).Error
	return
}

func (g *Goods) GetGoodsUpdate(goodsId, status int64) error {

	return DB.Model(&Goods{}).Where("goodsId = ?", goodsId).Update("status", status).Error

}
